package com.hgd.security.evp.biz.biz;

import com.hgd.security.evp.biz.entity.EvpGroupUser;
import com.hgd.security.evp.biz.mapper.EvpGroupUserMapper;
import com.hgd.security.evp.common.biz.BusinessBiz;
import com.hgd.security.evp.common.util.ObjectResultResponse;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * 
 *
 * @author By Shang
 * @email ${email}
 * @version 2019-01-01 22:49:10
 */
@Service
public class EGroupUserBiz extends BusinessBiz<EvpGroupUserMapper, EvpGroupUser> {
    /**
     * 添加记录
     * @param evpGroupUser 待添加记录
     * @return 结果
     */
    public ObjectResultResponse<Void> addEGroupUser(EvpGroupUser evpGroupUser) {
        ObjectResultResponse<Void> oResult=new ObjectResultResponse<>();
        this.insertSelectiveBindCrt(evpGroupUser);
        oResult.setMessage("添加用户--组记录成功");
        return oResult;
    }

    public ObjectResultResponse<Void> updateEGroupUser(EvpGroupUser evpGroupUser) {
        ObjectResultResponse<Void> oResult=new ObjectResultResponse<>();
        this.updateSelectiveByIdBindUpd(evpGroupUser);
        oResult.setMessage("更新用户--组记录成功");
        return oResult;
    }

    public ObjectResultResponse<Void> delEGroupUser(Integer id){
        ObjectResultResponse<Void> oResult=new ObjectResultResponse<>();
        this.deleteById(id);
        oResult.setMessage("删除用户--组记录成功");
        return oResult;
    }

    /**
     * 删除用户组关系
     * @param evpGroupUser
     * @return
     */
    public ObjectResultResponse<Void> delEGroupUser(EvpGroupUser evpGroupUser) {
        ObjectResultResponse<Void> restResult=new ObjectResultResponse<>();

        Example example=new Example(EvpGroupUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("groupId", evpGroupUser.getGroupId());
        criteria.andEqualTo("userId", evpGroupUser.getUserId());

        this.mapper.deleteByExample(example);

        restResult.setStatus(200);
        restResult.setMessage("删除组--用户关系成功");
        return restResult;
    }
}